ddaccordion.init({
	headerclass: "silverheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "mouseover", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: true, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "selected"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

function enableFields() {
	
	document.getElementById("employeeName").disabled=false;
	document.getElementById("emailId").disabled=false;
	document.getElementById("password").disabled=false;
	document.getElementById("roleId").disabled=false;
	document.getElementById("passportNo").disabled=false;
	document.getElementById("ppIssuingAuthority").disabled=false;
	document.getElementById("ppExpiryDate").disabled=false;
	document.getElementById("visaStatus").disabled=false;
	document.getElementById("reminderEmailCc").disabled=false;
	document.getElementById("employeeStatusOnChange").disabled=false;
	
	document.getElementById("saveUpdateButton").style.display="block";
	document.getElementById("updateButton").style.display="none";
}

function validateonSearchSubmit(theForm) {
	return true;
}
function validateFormBeforeSubmitForUpdateEmployee(theForm){
	alert("mmmmm");
	var reason = "";
	var employeeCode = validateMe(document.getElementById('employeeCode'),'Employee Code');
	reason += employeeCode;
	var employeeName = validateMe(document.getElementById('employeeName'),'Employee Name');
	reason += employeeName;
	var emailId = validateMe(document.getElementById('emailId'),'Email Id');
	reason += emailId;
	var password = validateMe(document.getElementById('password'),'Password');
	reason += password;
	var roleId = validateMe(document.getElementById('roleId'),'Role Id');
	reason += roleId;

	if (reason != "") {
		 alert("Errors:\n" + reason); 
		return false;
	} 
	document.forms["updateEmployee"].action = "employeeMaintenance.html?method=saveUpdateEmployee";
	document.forms.updateEmployee.submit();
}

function validateFormBeforeSubmitForAddEmployee(theForm){
	var reason = "";
	var employeeCode = validateMe(document.getElementById('employeeCode'),'Employee Code');
	reason += employeeCode;
	var employeeName = validateMe(document.getElementById('employeeName'),'Employee Name');
	reason += employeeName;
	var emailId = validateMe(document.getElementById('emailId'),'Email Id');
	reason += emailId;
	var password = validateMe(document.getElementById('password'),'Password');
	reason += password;
	var roleId = validateMe(document.getElementById('roleId'),'Role Id');
	reason += roleId;

	if (reason != "") {
		 alert("Errors:\n" + reason); 
		return false;
	} 
	document.forms["addEmployee"].action = "employeeMaintenance.html?method=saveEmployee";
	document.forms.addEmployee.submit();
}

function validateMe(fld,name) { 
	var error = "";

	if (fld.value == null || (fld.value != null && (fld.value.length == 0 || fld.value == "Select" ))) {
		fld.style.background = 'Yellow'; 
		error = name+" field has not been filled in.\n"
	} else {
		var numaric = fld.value;
		var alphaa = numaric.charAt(0);
		var chCode = alphaa.charCodeAt(0);
		if(chCode == "32"){
				fld.style.background = 'Yellow'; 
				error = name+" should not start with space.\n"
			}
		if(name == "Password"){
			if(fld.value.length>12){
			error = name +" should not be more than 12 characters.\n"
			}else if(fld.value.length<6 && fld.value.length>0){
				error = name +" should not be less than 6 characters.\n"
			}
		}
	//***********
		if(name == "Email Id"){
				var at="@"
				var dot="."
				var lat=fld.value.indexOf(at)
				var lstr=fld.value.length
				var ldot=fld.value.indexOf(dot)
				if (fld.value.indexOf(at)==-1){
					   error = name + " is not valid.\n"
		  
				}

				if (fld.value.indexOf(at)==-1 || fld.value.indexOf(at)==0 || fld.value.indexOf(at)==lstr){
					   error = name + " is not valid.\n"
		  
				}

				if (fld.value.indexOf(dot)==-1 || fld.value.indexOf(dot)==0 || fld.value.indexOf(dot)==lstr){
				    error = name + " is not valid.\n"
		    	}

				if (fld.value.indexOf(at,(lat+1))!=-1){
					error = name + " is not valid.\n"
		    	}

				if (fld.value.substring(lat-1,lat)==dot || fld.value.substring(lat+1,lat+2)==dot){
						error = name + " is not valid.\n"
				}

				if (fld.value.indexOf(dot,(lat+2))==-1){
					error = name + " is not valid.\n"
		    	}
		
				if (fld.value.indexOf(" ")!=-1){
					error = name + " is not valid.\n"
		    	}

 		 	}
	//***********
	}
	return error;  
	}

